package com.cy.pj.brand.service;

import com.cy.pj.brand.dao.BrandDao;
import com.cy.pj.brand.pojo.Brand;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class BrandServiceImpl implements BrandService{
   // private static final Logger log= LoggerFactory.getLogger(BrandServiceImpl.class);

    @Autowired
    private BrandDao brandDao;

    @Override
    public int updateBrand(Brand brand) {
        return brandDao.updateBrand(brand);
    }

    @Override
    public Brand findById(Integer id) {
        return brandDao.findById(id);
    }

    @Override
    public List<Brand> findBrands(String name) {
        long t1=System.currentTimeMillis();
        //log.info("start:{}", System.currentTimeMillis());
        List<Brand> list=brandDao.findBrands(name);
        long t2=System.currentTimeMillis();
        //log.info("end:{}", System.currentTimeMillis());
        log.info("findBrands->time->{}",(t2-t1));
        return list;
    }

    @Override
    public int deleteById(Integer id) {
        int rows=brandDao.deleteById(id);
        return rows;
    }

    @Override
    public int saveBrand(Brand brand) {
        return brandDao.insertBrand(brand);
    }


}
